{extend name="common@create" /}
{block name="formaa"}
	<div class="row cl">
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text radius size-XL" value="" placeholder="请扫码" id="info" name="info" onkeydown="saoma(event)" onclick="maselect()">
		</div>
	</div>
	<div class="row cl mt-20">
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text radius size-XL" value="" placeholder="在这里输入得分，并按“回车”键保存" id="defen" name="defen" onkeydown="defen(event)">
		</div>
	</div>

	<table id="table1" class="table table-border table-bordered table-hover table-bg table-sort mt-20">
		<thead>
			<tr class="text-c">
				<th>序号</th>
				<th>学校</th>
				<th>班级</th>
				<th>姓名</th>
				<th>学科 </th>
				<th>得分</th>
				<th>时间</th>
			</tr>
		</thead>
		<tbody id="addjg">
		</tbody>
		<thead>
			<tr class="text-c">
				<th>序号</th>
				<th>学校</th>
				<th>班级</th>
				<th>姓名</th>
				<th>学科 </th>
				<th>得分</th>
				<th>得分</th>
			</tr>
		</thead>
	</table>

{/block}
{block name="yanzheng"}
<script type="text/javascript">
	// 设置表单验证规则
	var myrules = {
			
		};

	// 设置表单提交方式
	var mytype = 'POST';
	// 声明变量
	var myinfo = [];
	var cnt = 1;
	// var myDate = new Date();//获取系统当前时间



	// 处理扫码获取的信息
	function saoma(obj)
	{
		if (obj.keyCode != 13)
		{
			return false;
		}

		// 获取扫码值并分割成数据
		myinfo = $('#info').val().split(',');

		// 查询并显示学生信息
		$.ajax({
			type: 'POST',
			url: "/chengji/read",
			data:{
				id:myinfo[0],
				ziduan:myinfo[1]
			},
			dataType: 'json',
			success: function(data){
				data['id'] = myinfo[0];
				data['ziduan'] = myinfo[1];
				df = data['zdstr'];
				df = data[df];
				myinfo = data;
				$('#info').val(myinfo['cj_school']['jiancheng'] + '   ' + myinfo['cj_banji']['title'] + '   ' + myinfo['cj_student']['xingming'] + '   ' + myinfo['zdname']);
				var zd = data['ziduan'];
				df>0 ? $('#defen').val(df) : $('#defen').val('');
				$('#defen').focus();
			},
			error:function(data) {
				$('#info').val('');
				$('#defen').val('');
				$('#info').focus();
			},
		});	
	}


	function maselect()
	{
		$('#info').val('');
		$('#defen').val('');
		myinfo = [];
	}


	$(document).ready(function(){
	   $('#info').focus();
	});

	

	// 得分文本框绑定回车键事件
	function defen(obj){ 

		// 不是回车退出 
		if (obj.keyCode != 13)
		{
			return false;
		}
		// 获取得分
		var df = $('#defen').val();
		// 不是数字退出
		if(isNaN(df))
		{
			return false;
		}
		// 得分不是0~100退出 
		if(df<0 || df>100)
		{
			return false;
		}
		// 不能被0.5整除退出
		if((df*10%5))
		{
			return false;
		}

		// 查询并显示学生信息
		$.ajax({
			type: 'POST',
			url: "/chengji/malu",
			data:{
				id:myinfo['id'],
				ziduan:myinfo['ziduan'],
				defen:df
			},
			dataType: 'json',
			success: function(data){
				if(data['val'] == 1)
				{
					var date = new Date();
					var hour = date.getHours();
					var minute = date.getMinutes();
					var second = date.getSeconds();
					var addtime = hour + ':' + minute + ':' + second;
					var str = '<tr><td>'+cnt+'</td><td>' + myinfo['cj_school']['jiancheng'] +'</td><td>' + myinfo['cj_banji']['title'] + '</td><td>'+myinfo['cj_student']['xingming']+'</td><td>'+myinfo['zdname']+'</td><td>'+data['defen']+'</td><td>'+addtime+'</td></tr>';
					cnt++;
					$('#addjg').prepend(str);
				}
			},
			error:function(data) {
			},
		});	
		$('#info').val('');
		$('#defen').val('');
		$('#info').focus();
	};
</script>
{/block}